#include <iostream>

int arr[31];
int dp[31][20001];

using namespace std;

int main()
{
    int v, n;
    cin >> v >> n;
    for (int i = 1; i <= n; i++)cin >> arr[i];

    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= v; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if (arr[i] <= j)
            {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - arr[i]] + arr[i]);
            }
        }
    }


    cout << (v - dp[n][v]) << endl;

    return 0;
}